package com.seari.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.seari.bean.IorBean;
import com.seari.pojo.MessageBean;
import com.seari.service.TrainService;
import com.seari.utils.StringHelper;

@RestController
@RequestMapping("train/")
public class TrainController
{
	@Autowired
	private TrainService trainService;
	
	/**
     * @apiGroup 列车IOR信息
     * @api {ALL} /train/getTrainIOR 列车IOR配置信息
     * @apiDescription 获取列车IOR配置信息
     * @apiParamExample 请求示例
     * /train/getTrainIOR
     * @apiSuccessExample 成功响应
     * HTTP/1.1 200
     * {
     *      lineId: '线路号',
     *      trainType: '车型信息',
     *      trainGroup: 'IOR系统列车编组号',
     *      atsTrain: 'ATS系统列车编号（groupId）'
     * }
     * @apiVersion 0.0.1
     */
	@RequestMapping("getTrainIOR")
	public MessageBean getTrainIOR()
	{
		MessageBean messageBean = new MessageBean();
		List<IorBean> iorBeans = trainService.getIorReference();
		if(CollectionUtils.isEmpty(iorBeans))
		{
			messageBean.setCode("500");
			messageBean.setType(StringHelper.MESSAGE_TYPE_ERROR);
		}else {
			messageBean.setCode("200");
			messageBean.setType(StringHelper.MESSAGE_TYPE_SUCCESS);
			messageBean.setData(iorBeans);
			messageBean.setTotal(iorBeans.size());
		}
		return messageBean;
	}
}
